package leetcodecompetition.S108;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: Siantar
 * @Date: 2023-07-08-23:26
 * @Description: 1.0
 */
public class T6928 {
    int[][][] dir = new int[][][]{{{-1, -1}, {-1, 0}, {0, -1}}, {{-1, 1}, {-1, 0}, {0, 1}}, {{1, -1}, {1, 0}, {-1, 0}}, {{1, 1}, {1, 0}, {0, 1}}};

    public long[] countBlackBlocks(int m, int n, int[][] coordinates) {

        long[] res = new long[5];
        res[0] = (long) (m - 1) * (n - 1);
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < coordinates.length; i++) {
            int x = coordinates[i][0], y = coordinates[i][1];
            for (int j = 0; j < 4; j++) {
                if (x + dir[j][0][0] >= 0 && x + dir[j][0][0] < m && y + dir[j][0][1] >= 0 && y + dir[j][0][1] < n) {
                    int p = 0;
                    for (int k = 0; k < 3; k++) {
                        if (set.contains((x + dir[j][k][0]) * 100000 + (y + dir[j][k][1]))) {
                            p++;
                        }
                    }
                    res[p]--;
                    res[p + 1]++;
                }
            }
            set.add(x * 100000 + y);
        }
        return res;
    }
}
